package com.wc.算法基础课.C第三讲搜索与图论.树与图的深度优先遍历.大臣的旅费;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/14 20:30
 * @description https://www.acwing.com/problem/content/1209/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010, M = N << 1;
    static int[] h = new int[N];
    static int[] e = new int[M];
    static int[] ne = new int[M];
    static int[] d = new int[M];
    static boolean[] st = new boolean[N];
    static int idx = 0;
    static int n;
    static int a, b, c;
    // 每个点下面最大的距离
    static int[] maxD = new int[N];
    static int ans = 0;


    public static void main(String[] args) {
        n = sc.nextInt();
        Arrays.fill(h, -1);
        for (int i = 1; i < n; i++) {
            a = sc.nextInt();
            b = sc.nextInt();
            c = sc.nextInt();
            add(a, b, c);
            add(b, a, c);
        }
        dfs(1);
        out.println((21L + ans) * ans / 2);
        out.flush();
    }

    static int dfs(int u) {
        st[u] = true;
        PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = h[u]; i != -1; i = ne[i]) {
            // u -> e[i]的距离
            int j = e[i];
            if (!st[j])
                q.add(dfs(j) + d[i]);
            else q.add(maxD[j]);
        }
        // 以当前点为转折点的，就拿到两个最大的值
        if (q.size() >= 2) {
            int a = q.poll();
            int b = q.peek();
            q.add(a);
            ans = Math.max(a + b, ans);
        }
        // 没有子节点
        if (q.isEmpty()) return 0;
        maxD[u] = q.peek();
        // 表示该点为起点的时候
        ans = Math.max(maxD[u], ans);
        return maxD[u];
    }

    static void add(int a, int b, int c) {
        e[idx] = b;
        // 存这条边的距离
        d[idx] = c;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}